home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
emulator
/
bsvc-1.000
/
bsvc-1
/
bsvc-1.0.4
/
src
/
Assemblers
/
hecasm
/
asm5.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-26
|
5KB
|
271 lines
/* here are the routines to handle outputing the object code and */
/* listing file */
#include "asm.h"
/* this is used if a byte addressable machine is chosen */
#if (WSIZE == 1)
outlisting()
{
register char *cp;
register int *wp;
int nwords;
/* fill end of buffer with spaces */
for(cp=eptr;cp<&ebuf[ERRMAX];*cp++ = ' ');
if (listmode == EMPTYLIS)
fprintf(lfp,"%.4s ",ebuf);
else
fprintf(lfp,"%.4s %.04x ",ebuf, listaddr);
if (listmode == NOCODLIS)
fprintf(lfp,"%17s%5d %s","",lineno, sbuf);
else
{
nwords = cptr - cbuf;
wp = &cbuf[0];
switch(nwords)
{
case 0:
fprintf(lfp,"%16s","");
break;
case 1:
fprintf(lfp,"%02x%14s",wp[0]&BYTE,"");
break;
case 2:
fprintf(lfp,"%02x %02x%10s",wp[0]&BYTE,wp[1]&BYTE,"");
break;
default:
fprintf(lfp,"%02x %02x %02x%6s",wp[0]&BYTE,wp[1]&BYTE,wp[2]&BYTE,"");
break;
}
fprintf(lfp,"%5d %s",lineno,sbuf);
wp += 3;
while ((nwords -= 3) > 0)
{
fprintf(lfp,"%11s","");
switch(nwords)
{
case 1:
fprintf(lfp,"%02x\n",wp[0]&BYTE);
break;
case 2:
fprintf(lfp,"%02x %02x\n",wp[0]&BYTE,wp[1]&BYTE);
break;
default:
fprintf(lfp,"%02x %02x %02x\n",wp[0]&BYTE,wp[1]&BYTE,wp[2]&BYTE);
}
wp +=3;
}
}
}
#else
/* this is compiled if it is a word addressable machine */
outlisting()
{
register char *cp;
register int *wp;
int nwords,address;
/* fill end of buffer with spaces */
for(cp=eptr;cp<&ebuf[ERRMAX];*cp++ = ' ');
fprintf(lfp,"%.4s %.04x ",ebuf, listaddr);
if (listmode == NOCODLIS)
fprintf(lfp,"%17s%5d %s","",lineno, sbuf);
else
{
nwords = cptr - cbuf;
wp = &cbuf[0];
switch(nwords)
{
case 0:
fprintf(lfp,"%16s","");
break;
case 1:
fprintf(lfp,"%04x%12s",wp[0]&WORD,"");
break;
case 2:
fprintf(lfp,"%04x %04x%7s",wp[0]&WORD,wp[1]&WORD,"");
break;
default:
fprintf(lfp,"%04x %04x %04x%2s",wp[0]&WORD,wp[1]&WORD,wp[2]&WORD,"");
break;
}
fprintf(lfp,"%5d %s",lineno,sbuf);
wp += 3;
address=listaddr;
while ((nwords -= 3) > 0)
{
fprintf(lfp,"%.4s %.04x ",ebuf, address += 3);
switch(nwords)
{
case 1:
fprintf(lfp,"%04x\n",wp[0]&WORD);
break;
case 2:
fprintf(lfp,"%04x %04x\n",wp[0]&WORD,wp[1]&WORD);
break;
default:
fprintf(lfp,"%04x %04x %04x\n",wp[0]&WORD,wp[1]&WORD,wp[2]&WORD);
}
wp +=3;
}
}
}
#endif
/*
* Output code word.
* Save it in the per line
* buffer for outlisting.
* Update dot.
*/
codew(b)
int b;
{
/* fake it on the first pass */
if (!pass)
{
dot->s_value++;
return;
}
/* mask it to the correct size */
#if (WSIZE == 1)
b &= 0x0ff;
#else
b &= 0x0ffff;
#endif
/* put it in the code buffer */
if(cptr < &cbuf[CLMAX])
*cptr++ = b;
else
err('d',"code buffer overflow");
/* if the buffer is full, or the code is non contiguous flush the buffer */
if (!nflag)
{
if(crec >= CBMAX || cadr + crec != dot->s_value)
{
cflush();
/* new buffer address */
cadr = dot->s_value;
}
crbf[crec++] = b;
}
/* increment the location counter */
dot->s_value++;
}
/*
* Flush the binary code
* buffer.
*/
cflush()
{
register int i;
if(crec == 0)
return;
fprintf(ofp,"%04x/",cadr);
for(i=0; i<crec; ++i)
{
#if (WSIZE == 1)
fprintf(ofp, "%02x", crbf[i]&BYTE);
#else
fprintf(ofp, "%04x", crbf[i]&WORD);
#endif
}
fprintf(ofp,"\n");
crec = 0;
}
err(c,s)
int c;
char *s;
{
if (!pass)
return;
fprintf(stderr,"%04d %s\n",lineno,s);
if(eptr >= &ebuf[ERRMAX])
{
fprintf(stderr,"\ntoo many errors on a line.\n");
exit(1);
}
*eptr++ = c;
}
/*
* Print out the symbol table to Listing
*/
symprt()
{
register struct sym *stp, *uptr;
register struct reflst *ref;
struct reflst *ref1, *ref2;
int i,r,symcnt = 0;
char c1;
fprintf(lfp,"\14\n");
uptr = &ust[USERMAX];
for (stp=ust; stp < uptr; stp++)
if (stp->s_used)
{
symcnt++;
if (stp->s_flag && SF_ASG)
c1 = '=';
else
c1 = ' ';
fprintf(lfp,"\t%-8s %c %04x ",stp->s_name,c1,stp->s_value);
ref1 = stp->s_ref;
ref = NULL;
while (ref1 != NULL)
{
ref2 = ref1;
ref1 = ref1->r_chain;
ref2->r_chain = ref;
ref = ref2;
}
i = LREFMAX;
while (ref!=NULL)
{
r=ref->r_stmtno;
if(r<0)
{
r = -r;
c1 = '#';
}
else
c1 = ' ';
fprintf(lfp,"%5d%c",r,c1);
ref=ref->r_chain;
i--;
if (!i && ref!=NULL)
{
fprintf(lfp,"\n\t\t\t ");
i=LREFMAX;
}
}
fprintf(lfp,"\n");
}
fprintf(lfp,"\n%6d Symbols\n%6d References\n",symcnt,refcnt);
return;
}